{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "toc": true
   },
   "source": [
    "<h1>目录<span class=\"tocSkip\"></span></h1>\n",
    "<div class=\"toc\"><ul class=\"toc-item\"></ul></div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "import time, threading\n",
    "def loop():\n",
    "    time.sleep(2)\n",
    "    print('thread %s is running...' % (threading.current_thread().name))    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "from concurrent.futures import ThreadPoolExecutor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "thread ThreadPoolExecutor-17_0 is running...\n",
      "thread ThreadPoolExecutor-17_1 is running...\n",
      "thread ThreadPoolExecutor-17_2 is running...\n",
      "thread ThreadPoolExecutor-17_3 is running...\n",
      "thread ThreadPoolExecutor-17_4 is running...\n",
      "thread ThreadPoolExecutor-17_0 is running...\n",
      "thread ThreadPoolExecutor-17_2 is running...\n",
      "thread ThreadPoolExecutor-17_1 is running...\n",
      "thread ThreadPoolExecutor-17_3 is running...thread ThreadPoolExecutor-17_4 is running...\n",
      "\n",
      "thread ThreadPoolExecutor-17_0 is running...\n",
      "thread ThreadPoolExecutor-17_4 is running...\n",
      "thread ThreadPoolExecutor-17_2 is running...thread ThreadPoolExecutor-17_1 is running...\n",
      "\n",
      "thread ThreadPoolExecutor-17_3 is running...\n"
     ]
    }
   ],
   "source": [
    "with ThreadPoolExecutor(max_workers=5) as ex:\n",
    "    for i in range(15):\n",
    "        future = ex.submit(loop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "base"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "目录",
   "title_sidebar": "大纲",
   "toc_cell": true,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
